package com.finer.service.impl;

import com.finer.entity.buy.FinerBuyBackOrder;
import com.finer.dao.FinerBuyBackOrderDao;
import com.finer.service.FinerBuyBackOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 采购退货订单表(FinerBuyBackOrder)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:36
 */
@Service("finerBuyBackOrderService")
public class FinerBuyBackOrderServiceImpl implements FinerBuyBackOrderService {
    @Resource
    private FinerBuyBackOrderDao finerBuyBackOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerBuyBackOrder queryById(Integer id) {
        return this.finerBuyBackOrderDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerBuyBackOrder 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerBuyBackOrder> queryByPage(FinerBuyBackOrder finerBuyBackOrder, PageRequest pageRequest) {
        long total = this.finerBuyBackOrderDao.count(finerBuyBackOrder);
        return new PageImpl<>(this.finerBuyBackOrderDao.queryAllByLimit(finerBuyBackOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerBuyBackOrder 实例对象
     * @return 实例对象
     */
    @Override
    public FinerBuyBackOrder insert(FinerBuyBackOrder finerBuyBackOrder) {
        this.finerBuyBackOrderDao.insert(finerBuyBackOrder);
        return finerBuyBackOrder;
    }

    /**
     * 修改数据
     *
     * @param finerBuyBackOrder 实例对象
     * @return 实例对象
     */
    @Override
    public FinerBuyBackOrder update(FinerBuyBackOrder finerBuyBackOrder) {
        this.finerBuyBackOrderDao.update(finerBuyBackOrder);
        return this.queryById(finerBuyBackOrder.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerBuyBackOrderDao.deleteById(id) > 0;
    }
}
